package com.example.demo.internettongxin.inetAdress;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * @Description IpTest1
 * @Author songchuanlong
 * @Date 2025-05-28
 */
public class IpTest1 {
    public static void main(String[] args) throws Exception {
        //1、获取本机ip地址
        InetAddress ip1 = InetAddress.getLocalHost();
        System.out.println(ip1.getHostName());
        System.out.println(ip1.getHostAddress());

        //2、获取指定ip或者域名的ip地址对象
        InetAddress baiDu = InetAddress.getByName("www.baidu.com");
        System.out.println(baiDu.getHostName());
        System.out.println(baiDu.getHostAddress());

        //3、看看百度和我自己的机器是否联通
        boolean reachable = baiDu.isReachable(6000);
        System.out.println(reachable);
    }
}
